package com.shop.cereshop.app.dl.logic.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.cereshop.app.dao.distributor.CereShopCommissionRecordDao;
import com.shop.cereshop.app.dao.distributor.CereShopDistributorDAO;
import com.shop.cereshop.app.dl.logic.domain.CereShopCommissionRecord;
import com.shop.cereshop.app.dl.logic.service.CereShopCommissionRecordService;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.domain.distributor.CereShopDistributor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 况鑫威
 * @Date: 2021/7/20
 * @Time: 10:09
 * @ClassName: CereShopCommissionRecordServiceImpl
 * @Description: com.shop.cereshop.app.dl.logic.service.Impl
 */
@Service
public class CereShopCommissionRecordServiceImpl implements CereShopCommissionRecordService {

    @Autowired
    private CereShopCommissionRecordDao cereShopCommissionRecordDao;

    @Autowired
    private CereShopDistributorDAO cereShopDistributorDAO;


    @Override
    public int deleteByPrimaryKey(Long commissionRecordId) {
        return cereShopCommissionRecordDao.deleteByPrimaryKey(commissionRecordId);
    }

    @Override
    public int insert(CereShopCommissionRecord record) {
        return cereShopCommissionRecordDao.insert(record);
    }

    @Override
    public int insertSelective(CereShopCommissionRecord record) {
        return cereShopCommissionRecordDao.insertSelective(record);
    }

    @Override
    public CereShopCommissionRecord selectByPrimaryKey(Long commissionRecordId) {
        return cereShopCommissionRecordDao.selectByPrimaryKey(commissionRecordId);
    }

    @Override
    public int updateByPrimaryKeySelective(CereShopCommissionRecord record) {
        return cereShopCommissionRecordDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CereShopCommissionRecord record) {
        return cereShopCommissionRecordDao.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<CereShopCommissionRecord> getCommissionRecords(CereBuyerUser user, Integer page, Integer row) {
        //查询关联的分销数据
        CereShopDistributor cereShopDistributor = cereShopDistributorDAO.findByBuyerUserId(user.getBuyerUserId());
        PageHelper.startPage(page, row);
        List<CereShopCommissionRecord> cereShopCommissionRecords = cereShopCommissionRecordDao.selectBydistributorId(cereShopDistributor.getDistributorId());
        //查询数据返回集合
        return new PageInfo<>(cereShopCommissionRecords);
    }


}
